
$(function(){
  $('#btnGetFT').click(function(argument) {
    var $grid = $('#FreightTieredGrid').grid();
    //alert(setting);
    BindPager($grid ? $grid.GetSetting() : FreightTieredGridSetting());
  })
});

function BindPager(setting, callback) {
  
  var uri = 'http://localhost:18998/api/FreightTiered/GetPager/';

  var query = {
      "CreateTimeFrom": '2016-06-15',
      "CreateTimeTo": '2016-06-15',
      "AduitTimeFrom": '2016-06-15',
      "AduitTimeTo": '2016-06-15',
      "ChannelSysNoArray": [],
      "WebSiteSysNoArray": [],
      "StockSysNoArray": [],
      "StatusArray": [],
      "Query": {PageIndex: setting.pageindex, PageSize: setting.pagesize, Model: null}
  };
  //query = JSON.stringify(query);

  $.post(uri, query, function(res) {
    if(res.Code == 100 && res.Value && res.Value.ModelList && res.Value.RecordCount){
     setting.data = res.Value.ModelList;
     setting.total = res.Value.RecordCount;
     if (callback)
         callback(setting);
     else
         $('#' + setting.id).grid(setting);

      return true;
    }
    alert("error:" + res.Msg)
  })

}

function FreightTieredGridSetting() {
  var setting = { id: "FreightTieredGrid"
    , key: "SysNo"
    , title: { label: 'Data Grid Title..' }
    , cols: [], data: [], toolbar: {}
    , checkbox : true
    , rowindex: false
    , pageindex: 1
    , pagesize: 5
    , isfix: true
  };

  setting.cols.push({ key: "SysNo", type: "string", width: 80, label: "SysNo" });
  setting.cols.push({ key: "ChannelSysNo", type: "string", width: 80, label: "ChannelSysNo" });
  setting.cols.push({ key: "WebSiteSysNo", type: "string", width: 80, label: "WebSiteSysNo" });
  setting.cols.push({ key: "StockSysNo", type: "string", width: 80, label: "StockSysNo" });
  setting.cols.push({ key: "AduitUserSysNo", type: "string", width: 80, label: "AduitUserSysNo" });
  setting.cols.push({ key: "AduitTime", type: "string", width: 180, label: "AduitTime" });
  setting.cols.push({ key: "Status", type: "string", width: 80, label: "Status" });
  setting.cols.push({ key: "CreateUserSysNo", type: "string", width: 80, label: "CreateUserSysNo" });
  setting.cols.push({ key: "CreateTime", type: "string", width: 180, label: "CreateTime" });
  setting.cols.push({ key: "LastUpdateUserSysNo", type: "string", width: 80, label: "LastUpdateUserSysNo" });
  setting.cols.push({ key: "LastUpdateTime", type: "string", width: 180, label: "LastUpdateTime" });

  // setting.cols.push({ key: "Status", type: "string", width: 80, label: "Status" });
  // setting.cols.push({ key: "CreateUserSysNo", type: "string", width: 80, label: "CreateUserSysNo" });
  // setting.cols.push({ key: "CreateTime", type: "string", width: 180, label: "CreateTime" });
  // setting.cols.push({ key: "LastUpdateUserSysNo", type: "string", width: 80, label: "LastUpdateUserSysNo" });
  // setting.cols.push({ key: "LastUpdateTime", type: "string", width: 180, label: "LastUpdateTime" });

  setting.pager = BindPager;

  // setting.edit = { No3: {}};
  // setting.edit.No3.editpanel = '<input type="text" style="width:200px;" />';

  return setting;
}